<!doctype html>
<html>

	<head>
		<meta charset="utf-8">
		<title></title>
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<link href="./css/mui.min.css" rel="stylesheet" />
		<link rel="stylesheet" type="text/css" href="css/arrearsInquery.css" />
		<link rel="stylesheet" type="text/css" href="css/loading.css"/>
	</head>

	<body>
		<div class="user-inquery">
			<div class="user-inquery-all">
				<div class="displayCount">
					<!-- 选择top数 -->
					<div class="displayCountText">
						显示:
					</div>
					<div class="mui-select">
						<select name="" id="topSec">
							<option value="">100</option>
							<option value="">1000</option>
							<option value="">10000</option>
							<option value="">所有</option>
						</select>
					</div>
				</div>
				<div class="user-inquery-input">
					<input id="userId" type="text" class="mui-input-clear" placeholder="用户号或用户名">
					<button id="userInquery" type="button" class="mui-btn mui-btn-primary">查询</button>
				</div>
			</div>
			
			
		</div>
		<div class="user-lists">
			<div class="user-lists-total">
				<span class="user-lists-total-title">合计金额：</span>
				<span class="user-lists-total-value" id="totalMoneys"></span>
				<span id="peopleNumber" class="people"></span>
			</div>
			<ul class="mui-table-view">
			</ul>
		</div>

		<script src="./js/mui.min.js"></script>
		<script src="js/jquery-2.1.1.min.js" type="text/javascript" charset="utf-8"></script>
		<script src="js/Mobile.js" type="text/javascript" charset="utf-8"></script>
		<script src="js/app.js" type="text/javascript" charset="utf-8"></script>
		<script src="js/loading.js" type="text/javascript" charset="utf-8"></script>
		<script type="text/javascript">
			mui.init();
			mui('.user-inquery-input').on('tap', '#userInquery', function() {
				var myStorage = JSON.parse(localStorage.getItem("users"));
				var glbToken = myStorage.glbToken;
				mui.showLoading("正在加载中..","div");
				if (checkToken(glbToken).status == "ok") {
					var userId = $('#userId').val();
					var topSec = $("#topSec option:selected").text();
					if (topSec == "所有") {
						topSec = "所有"
					} else{
						topSec = topSec - 1
					}
					var oweFee = getOwefee(userId, topSec, glbToken).rows;
					if (oweFee.length == 0) {
						mui.hideLoading();
						alert('无记录')
						return false
					}
					var listsDom = document.getElementsByClassName('mui-table-view')[0];
					var lists = "";
					var oweFeeTotalMoney = 0;
					setTimeout(function(){
						for (var i = 0; i < oweFee.length; i++) {
							lists += "<li class='mui-table-view-cell user-li'>" +
								"<a href='javascript:;'>" +
								"<div class='user-info'>用户名：" + oweFee[i].UserName + "</div>" +
								"<div class='user-info'>用户号：" + oweFee[i].UserID + "</div>" +
								"<div class='user-info'>欠费年月：" + oweFee[i].ReadCodeDate + "</div>" +
								"<div class='user-info'>总欠费：" + oweFee[i].TotalMoney + "</div>" +
								"<div class='user-info' style='display: none;'>" + oweFee[i].WRSID + "</div>" +
								"</a>" + "</li>"
							if (i == oweFee.length-1) {
								mui.hideLoading();
							}
							oweFeeTotalMoney += parseFloat(oweFee[i].TotalMoney);
						}
						listsDom.innerHTML = lists;
						document.getElementById('totalMoneys').innerHTML = oweFeeTotalMoney.toFixed(2) + '元';
						document.getElementById('peopleNumber').innerHTML = '共' + oweFee.length + '人次';
						$(".user-li").each(function(i, n) {
							$(".user-li")[i].onclick = function() {
								var userId = n.getElementsByTagName('div')[1].innerText.substr(4);
								var userName = n.getElementsByTagName('div')[0].innerText.substr(4);
								var WRSID = n.getElementsByTagName('div')[4].innerText;
								mui.openWindow({
									url: "oweFee.html",
									id: "oweFee.html",
									extras:{
										token: glbToken,
										userid: userId,
										userName: userName,
										wrsid: WRSID,
										topSec:topSec
									}
								})
							}
						})
					},100)
				} else {
					app.setState({});
					plus.webview.getLaunchWebview().show("pop-in");
					setTimeout(function() {
						alert("此账号已在其他设备登录,请重新登录!");
						localStorage.clear();
						plus.runtime.restart();
					}, 30);
				}
			})
			
			// 跳转到详情页
			
		</script>
	</body>

</html>
